package org.freemarker.core.service.impl;

import javax.persistence.NoResultException;

import org.freemarker.core.dao.EntityJpaDao;
import org.freemarker.core.dao.UserDao;
import org.freemarker.core.model.Contact;
import org.freemarker.core.model.User;
import org.freemarker.core.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements
		UserService {

	private static final Logger logger = LoggerFactory
			.getLogger(UserServiceImpl.class);

	@Autowired
	@Qualifier("userDaoImpl")
	public void setEntityJpaDao(EntityJpaDao<User> entityJpaDao) {
		this.entityJpaDao = entityJpaDao;
	}

	@Override
	public User getUserByUsername(String username) {
		return ((UserDao) entityJpaDao).getUserByUsername(username);
	}

	@Override
	public boolean validLogin(String user, String pass) {
		boolean valid = false;
		User u = ((UserDao) entityJpaDao).getUserByUsername(user);
		if (u != null) {
			String correctPassword = u.getPassword();
			if (pass.equals(correctPassword))
				valid = true;
		}
		return valid;
	}

}
